<?php
/**
 * @subpackage Components
 * @link http://docs.joomla.org/Developing_a_Model-View-Controller_Component_-_Part_1
 * @license    GNU/GPL
*/
 
// no direct access
 
defined( '_JEXEC' ) or die( 'Restricted access' );
 
jimport( 'joomla.application.component.view');
jimport( 'joomla.application.application' );
jimport( 'joomla.methods' );

/**
 * HTML View class for the HelloWorld Component
 *
 * @package    HelloWorld
 */
 
class HizkuntzakViewHizkuntzak extends JView
{
    function display($tpl = null)
    {
        $this->addCSS();
		$this->addJavascripts();
		
        $model = &$this->getModel();
        
        $rsc = $model->selectLangRsc();
		$this->assignRef('rsc',$rsc);
		
		$c_lang = $model->checkLang();
		$this->assignRef('c_lang', $c_lang);
		
		$langs = $model->getAllLangs($c_lang, 1);
		$this->assignRef('langs',$langs);
		
		$user =& JFactory::getUser();
		$show = false;
		
		if($user->id != 0){
			$show = true;
		}
		
		$this->assignRef('show',$show);
		
		$this->assignRef('imgs' , $model->getRandomImages());

        parent::display($tpl);
    }
    
    function firstWords($tpl = null){
    	
    	if(!$this->checkLangSel()){
			$link = 'index.php?option=com_hizkuntzak';
			JApplication::redirect($link, $msg='', $msgType='message');			
		}
		
    	$this->addCSS();
		$this->addJavascripts();
    	
    	$model = &$this->getModel();
        
        $rsc = $model->selectLangRsc();
		$this->assignRef('rsc',$rsc);
 		
		$infoLang = $model->getLangInfo();
		$this->assignRef('wordsLang', $infoLang);
		
		$c_lang = $model->checkLang();
		$this->assignRef('c_lang', $c_lang);
		
		$lang = $model->getLang();
		$this->assignRef('lang', $lang);

		$langs = $model->getAllLangs($c_lang, 1);
		$this->assignRef('langs',$langs);
		
		$user =& JFactory::getUser();
		$show = false;
		
		if($user->id != 0){
			$show = true;
		}
		
		$this->assignRef('show',$show);
		
        parent::display($tpl);
    }
    
	function qas($tpl = null){
    	
    	if(!$this->checkLangSel()){
			$link = 'index.php?option=com_hizkuntzak';
			JApplication::redirect($link, $msg='', $msgType='message');			
		}
		
    	$this->addCSS();
		$this->addJavascripts();
    	
    	$model = &$this->getModel();
        
        $rsc = $model->selectLangRsc();
		$this->assignRef('rsc',$rsc);
 		
		$infoLang = $model->getLangQas();
		$this->assignRef('qasLang', $infoLang);
		
		$c_lang = $model->checkLang();
		$this->assignRef('c_lang', $c_lang);
		
		$lang = $model->getLang();
		$this->assignRef('lang', $lang);

		$langs = $model->getAllLangs($c_lang, 1);
		$this->assignRef('langs',$langs);
		
		$user =& JFactory::getUser();
		$show = false;
		
		if($user->id != 0){
			$show = true;
		}
		
		$this->assignRef('show',$show);
		
        parent::display($tpl);
    }
    
	function whospeaks($tpl = null){
    	
		if(!$this->checkLangSel()){
			$link = 'index.php?option=com_hizkuntzak';
			JApplication::redirect($link, $msg='', $msgType='message');			
		}
		
    	$this->addCSS();
		$this->addJavascripts();
    	
    	$model = &$this->getModel();
        
        $rsc = $model->selectLangRsc();
		$this->assignRef('rsc',$rsc);
 		
		$c_lang = $model->checkLang();
		$this->assignRef('c_lang', $c_lang);
		
		$lang = $model->getLang();
		$this->assignRef('lang', $lang);

		$langs = $model->getAllLangs($c_lang, 1);
		$this->assignRef('langs',$langs);

		$user =& JFactory::getUser();
		$show = false;
		
		if($user->id != 0){
			$show = true;
		}
		
		$this->assignRef('show',$show);
		
        parent::display($tpl);
    }
    
	function numbers($tpl = null){
    	
		if(!$this->checkLangSel()){
			$link = 'index.php?option=com_hizkuntzak';
			JApplication::redirect($link, $msg='', $msgType='message');			
		}
		
    	$this->addCSS();
		$this->addJavascripts();
    	
    	$model = &$this->getModel();
        
        $rsc = $model->selectLangRsc();
		$this->assignRef('rsc',$rsc);
 		
		$numberLang = $model->getNumbers();
		$this->assignRef('numbersLang', $numberLang);
		
		$c_lang = $model->checkLang();
		$this->assignRef('c_lang', $c_lang);
		
		$lang = $model->getLang();
		$this->assignRef('lang', $lang);
		
		$langs = $model->getAllLangs($c_lang, 1);
		$this->assignRef('langs',$langs);

		$user =& JFactory::getUser();
		$show = false;
		
		if($user->id != 0){
			$show = true;
		}
		
		$this->assignRef('show',$show);
		
        parent::display($tpl);
    }
    
	function songs($tpl = null){
    	
		if(!$this->checkLangSel()){
			$link = 'index.php?option=com_hizkuntzak';
			JApplication::redirect($link, $msg='', $msgType='message');			
		}
		
    	$this->addCSS();
		$this->addJavascripts();
    	
    	$model = &$this->getModel();
        
        $rsc = $model->selectLangRsc();
		$this->assignRef('rsc',$rsc);
 		
		$songsLang = $model->getSongs();
		$this->assignRef('songsLang', $songsLang);
		
		$c_lang = $model->checkLang();
		$this->assignRef('c_lang', $c_lang);
		
		$lang = $model->getLang();
		$this->assignRef('lang', $lang);
		
		$langs = $model->getAllLangs($c_lang, 1);
		$this->assignRef('langs',$langs);

		$user =& JFactory::getUser();
		$show = false;
		
		if($user->id != 0){
			$show = true;
		}
		
		$this->assignRef('show',$show);
		
        parent::display($tpl);
    }
    
	function mainMenu($tpl = null){
    	
		if(!$this->checkLangSel()){
			$link = 'index.php?option=com_hizkuntzak';
			JApplication::redirect($link, $msg='', $msgType='message');			
		}
		
    	$this->addCSS();
		$this->addJavascripts();
    	
    	$model = &$this->getModel();
        
        $rsc = $model->selectLangRsc();
		$this->assignRef('rsc',$rsc);
		
		$c_lang = $model->checkLang();
		$this->assignRef('c_lang', $c_lang);
		
		$lang = $model->getLang();
		$this->assignRef('lang', $lang);

		$langs = $model->getAllLangs($c_lang, 1);
		$this->assignRef('langs',$langs);
		
        parent::display($tpl);
    }
    
    function adminHizkuntzak($tpl = null){
    	
    	$this->addCSS();
		$this->addJavascripts();
    	
    	$model = &$this->getModel();
        
        $rsc = $model->selectLangRsc();
		$this->assignRef('rsc',$rsc);
		
		$c_lang = $model->checkLang();
		$this->assignRef('c_lang', $c_lang);
		
		$langs = $model->getAllLangs($c_lang, 0);
		$this->assignRef('langs',$langs);
		
		$words = $model->getAllWords(0);
		$this->assignRef('words',$words);
		
		$qas = $model->getAllQAs(0);
		$this->assignRef('qas',$qas);
		
		parent::display($tpl);
    }
    
    private function checkLangSel(){
    	$code = JRequest::getString('hlang');
		
    	if($code != '' && $code != null){
    		$_SESSION['hizkLang'] = $code;
    		return true;
    	}
		else if($_SESSION['hizkLang'] != null && $_SESSION['hizkLang'] != ''){

			return true;
		}
		else {

			return false;
		}
    }
    
	private function addCSS(){
		$option=JRequest::getCmd('option');
			
		$document=&JFactory::getDocument();
			
		$document->addStyleSheet('components/'.$option.'/css/smoothness/jquery-ui-1.8.15.custom.css');
		$document->addStyleSheet('components/'.$option.'/css/validationEngine.jquery.css');
		$document->addStyleSheet('components/'.$option.'/css/demo_table.css');
	}
	
	private function addJavascripts(){
			$option=JRequest::getCmd('option');
			
			$document=&JFactory::getDocument();
			
			$document->addScript('components/'.$option.'/js/jquery-1.6.2.min.js');
			$document->addScript('components/'.$option.'/js/jquery-ui-1.8.15.custom.min.js');

			$document->addScript('components/'.$option.'/js/jquery.dataTables.js');
			
			$document->addScript('components/'.$option.'/js/hizkuntzak-main.js');
						
	}
}

